package com.hspedu.reflection.homework;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author DL5O
 * @version 1.0
 */
public class Homework02 {
    public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, IOException {
        Class<File> fileClass = File.class;//得到File Class对象
        Constructor<?>[] fileConstructors = fileClass.getDeclaredConstructors();
        //打印该类所有的构造器
        for (Constructor<?> fileConstructor : fileConstructors) {
            System.out.print("构造器名:" + fileConstructor.getName());
            System.out.print(" 参数列表:");
            Class<?>[] parameterTypes = fileConstructor.getParameterTypes();
            for (Class<?> parameterType : parameterTypes) {
                System.out.print("" + parameterType.getName()+" ");
            }
            System.out.println();
        }
        String filePath = "D:\\1.txt";
        //创建file对象
        Constructor<File> fileConstructor = fileClass.getDeclaredConstructor(String.class);
        File file = fileConstructor.newInstance(filePath);
        Method createNewFile = fileClass.getMethod("createNewFile");
        boolean newFile = (Boolean)createNewFile.invoke(file);

//        boolean newFile = file.createNewFile();
        
    }
}
